package com.gs.gaosheng.controller.web;

import com.gs.common.annotation.Log;
import com.gs.common.core.controller.BaseController;
import com.gs.common.core.domain.AjaxResult;
import com.gs.common.core.page.TableDataInfo;
import com.gs.common.enums.BusinessType;
import com.gs.common.utils.poi.ExcelUtil;
import com.gs.gaosheng.domain.GsType;
import com.gs.gaosheng.service.GsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品类型Controller
 *
 * @author yy
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/gaosheng/type/web")
public class GsTypeWebController extends BaseController
{
    @Autowired
    private GsTypeService gsTypeService;

    /**
     * 查询商品类型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GsType gsType)
    {
        startPage();
        List<GsType> list = gsTypeService.selectGsTypeList(gsType);
        return getDataTable(list);
    }

    /**
     * 导出商品类型列表
     */
    @Log(title = "商品类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GsType gsType)
    {
        List<GsType> list = gsTypeService.selectGsTypeList(gsType);
        ExcelUtil<GsType> util = new ExcelUtil<GsType>(GsType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 获取商品类型详细信息
     */
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return AjaxResult.success(gsTypeService.selectGsTypeById(typeId));
    }

    /**
     * 新增商品类型
     */
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GsType gsType)
    {
        return toAjax(gsTypeService.insertGsType(gsType));
    }

    /**
     * 修改商品类型
     */
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GsType gsType)
    {
        return toAjax(gsTypeService.updateGsType(gsType));
    }

    /**
     * 删除商品类型
     */
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(gsTypeService.deleteGsTypeByIds(typeIds));
    }
}
